<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\RegisterRequest;
use App\Repositories\UserRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class UserController extends Controller
{
    protected $userRepo;
    public  function  __construct(UserRepository $userRepo)
    {
        $this->userRepo = $userRepo;
    }

    /**
     * Method : 用户注册
     * User: berger
     * DateTime: 2021/8/18 17:27
     * @param Request $request
     */
    public function register(RegisterRequest $request)
    {
        $this->userRepo->register($request->all());

        return   $this->success();
    }

    /**
     * Method : 用户登录
     * User: berger
     * DateTime: 2021/8/23 14:10
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\coopException
     */
    public function login(Request $request)
    {
        $token =  $this->userRepo->login($request->all());
        return   $this->success($token);
    }

    public function  getUserInfo(Request $request)
    {
        $user =  $this->userRepo->getUserInfo($this->userId());
        return $this->success($user);
    }
}
